package com.bluemedia.bookproject.pages;

import com.vaadin.ui.Button;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import org.vaadin.navigator7.Page;

/**
 * Created by IntelliJ IDEA.
 * User: Marek Rucki
 * Date: 13.04.11
 * Time: 11:39
 */
@Page
public class TextFieldSample extends VerticalLayout implements Button.ClickListener {

    Button commentButton;
    TextField commentField = new TextField("Comment");
    TextField logField = new TextField("Log");

    public TextFieldSample() {
        super();
        setSpacing(true);
        commentButton = new Button("Add the comment to the log", this);

        // Add a single-line text field.
        commentField.setColumns(40);
        commentField.setValue("Enter your comment here");
        this.addComponent(commentField);

        this.addComponent(commentButton);
        // Add a multi-line text field.
        logField.setRows(7);
        logField.setColumns(40);
        this.addComponent(logField);
    }

    public void buttonClick(Button.ClickEvent event) {
        // Add the entered comment to the previous log text.
        // The "\n" causes a line return after each comment insertion.
        logField.setValue((String) logField.getValue() + (String) commentField.getValue() + "\n");
    }
}

